home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ohlutil.zip / CP-AUX.C < prev    next >
C/C++ Source or Header  |  1990-05-23  |  3KB  |  118 lines

  1. /*  cp-aux.c  -- file copying (auxiliary routines)
  2.     Copyright (C) 1989, 1990 Free Software Foundation.
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 1, or (at your option)
  7.     any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     Written by Torbjorn Granlund, Sweden (tege@sics.se).
  19. */
  20.  
  21. #include <stdio.h>
  22.  
  23. #include "cp.h"
  24.  
  25. extern char *program_name;
  26.  
  27. void
  28. usage (reason)
  29.      char *reason;
  30. {
  31.   if (reason != NULL)
  32.     fprintf (stderr, "%s: %s\n", program_name, reason);
  33.  
  34.   fprintf (stderr, "\
  35. Usage: %s [-bdfioprvR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  36.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  37.        [+preserve] [+recursive] [+verbose] [+suffix backup-suffix]\n\
  38.        [+version-control {numbered,existing,simple}] source dest\n\
  39. \n\
  40.        %s [-bdfioprvR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  41.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  42.        [+preserve] [+recursive] [+verbose] [+suffix backup-suffix]\n\
  43.        [+version-control {numbered,existing,simple}] source... directory\n",
  44.        program_name, program_name);
  45.  
  46.   exit (2);
  47. }
  48.  
  49. char *
  50. xmalloc (size)
  51.      unsigned size;
  52. {
  53.   char *x = malloc (size);
  54.   if (x == 0)
  55.     error (1, 0, "virtual memory exhausted");
  56.   return x;
  57. }
  58.  
  59. char *
  60. xrealloc (ptr, size)
  61.      char *ptr;
  62.      unsigned size;
  63. {
  64.   char *x = realloc (ptr, size);
  65.   if (x == 0)
  66.     error (1, 0, "virtual memory exhausted");
  67.   return x;
  68. }
  69.  
  70. char *
  71. str_cpy (s1, s2)
  72.      char *s1;
  73.      char *s2;
  74. {
  75.   while ((*s1++ = *s2++) != '\0')
  76.     ;
  77.   return s1 - 1;
  78. }
  79.  
  80. int
  81. yesno ()
  82. {
  83.   int c, t;
  84.  
  85.   fflush (stderr);
  86.   c = t = getchar ();
  87.   while (t != EOF && t != '\n')
  88.     t = getchar ();
  89.   return c == 'y' || c == 'Y';
  90. }
  91.  
  92. int
  93. is_ancestor (sb, ancestors)
  94.      struct stat *sb;
  95.      struct dir_list *ancestors;
  96. {
  97.   while (ancestors != 0)
  98.     {
  99.       if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev)
  100.     return 1;
  101.       ancestors = ancestors->parent;
  102.     }
  103.   return 0;
  104. }
  105.  
  106. /* Remove trailing slashes from PATH; they cause some system calls to fail. */
  107.  
  108. void
  109. strip_trailing_slashes (path)
  110.      char *path;
  111. {
  112.   int last;
  113.  
  114.   last = strlen (path) - 1;
  115.   while (last > 0 && path[last] == '/')
  116.     path[last--] = '\0';
  117. }
  118.